package com.tanhua.manager.service;

import com.tanhua.domain.db.Log;
import com.tanhua.dubbo.api.db.AnalysisByDayApi;
import com.tanhua.dubbo.api.db.LogApi;
import org.apache.dubbo.config.annotation.Reference;
import org.joda.time.DateTime;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class LogService {

    @Reference
    private LogApi logApi;
    @Reference
    private AnalysisByDayApi analysisByDayApi;

    public void save(Log log) {
        logApi.save(log);
    }


    /*
    管理系统，首页新增、活跃用户、次日留存率展示
    By Dzh
     */
    public ResponseEntity users(Long sd, Long ed, Integer type) {
        Long startDay = new DateTime(sd).getMillis();
        Long endDay = new DateTime(ed).getMillis();
        Map<String, List<Object>> map = analysisByDayApi.queryThisYear(startDay,endDay,type);
        return ResponseEntity.ok(map);
    }
}
